package servlet;

import entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@WebServlet(value = "/el")
public class ElServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setAttribute("key1", 123);
        req.getSession().setAttribute("key1", "session");
        getServletContext().setAttribute("key1", "application");

        //pageContext  < req < session < application


        req.setAttribute("key2", "value2");

        req.setAttribute("key3", new User(1L, "lisi", "123"));

        String[] arr = {"a1", "a2", "a3"};
        req.setAttribute("key4", arr);

        List<User> users = new ArrayList<>();
        users.add(new User(1L, "lisi", "123"));
        users.add(new User(2L, "admin", "admin"));
        req.setAttribute("key5", users);

        Map<String, User> map = new HashMap<>();
        map.put("a1", new User(1L, "lisi", "123"));
        map.put("a2", new User(2L, "admin", "admin"));
        req.setAttribute("key6", map);

        req.getRequestDispatcher("el.jsp").forward(req, resp);
    }
}
